package utils;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import java.util.StringTokenizer;
import org.biojava.bio.BioException;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.seq.RNATools;
import org.biojavax.Namespace;
import org.biojavax.RichObjectFactory;
import org.biojavax.bio.seq.RichSequence;
import org.biojavax.bio.seq.RichSequenceIterator;

public class SequenceDatabase {
	private List treeList = new ArrayList();
	private List namesList = new ArrayList();
	private List sequenceList = new ArrayList();

	public SequenceDatabase(String fileName) throws NoSuchElementException,
			BioException, FileNotFoundException {
		BufferedReader br = new BufferedReader(new FileReader(fileName));
		Namespace ns = RichObjectFactory.getDefaultNamespace();
		RichSequenceIterator seqs = RichSequence.IOTools.readFastaRNA(br, ns);
		int i = 0;
		while (seqs.hasNext()) {
			RichSequence rs = seqs.nextRichSequence();
			namesList.add(rs.getName());
			sequenceList.add(rs.seqString());
			if (i % 1000 == 0)
				System.out.println(i);
			i++;
		}
		System.out.println("----------------------------------------------");
		System.out.println("number of sequences:" + sequenceList.size());
		System.out.println("-------END of DATABASE------------");

	}

	public int size() {
		return namesList.size();
	}

	public String getSequence(int index) {
		return (String) sequenceList.get(index);
	}

	public String getName(int index) {
		return (String) namesList.get(index);
	}

}
